<?php
namespace app\admin\controller;

use think\Controller;
use Common\Controller\BaseController;
use think\Request;
use think\Session;


class Authentication extends Controller
{
    public function index(){
        return $this->fetch();
    }
    //已认证开始
    public function loan(){
        $user = session('user');
        //dump($user);exit;

        if(!$user){
            header("Refresh:1;url=login");
        }
        //$operation['operation']=$user = session('user.name');
        $examine['examine'] = 1;
        $res=db('user')->where($examine)->order('id Desc')->paginate(10);
        $page =  $res->render();
        $this->assign('page',$page);
        $this->assign('list',$res);
        //dump($res);exit;
        return $this->fetch();
    }
    public function uncertified(){
        $user = session('user');
        //dump($user);exit;

        if(!$user){
            header("Refresh:1;url=login");
        }
        //$operation['operation']=$user = session('user.name');
        $examine['examine'] = 0;
        $res=db('user')->where($examine)->order('id Desc')->paginate(10);
        $page =  $res->render();
        $this->assign('page',$page);
        $this->assign('list',$res);
        //dump($res);exit;
        return $this->fetch();
    }
    public function loan_insert(){
        $user = session('user');
        //dump($user);exit;
        if(!$user){
            header("Refresh:1;url=login");
        }
        return $this->fetch();
    }
    public function expressadd(){
        $user = session('user');
        //dump($user);exit;
        if(!$user){
            header("Refresh:1;url=login");
        }
        if(!$_POST) {
            $this->success('提交不能为空', 'express');
        }
        //$data = $_POST;
        //dump($_POST);exit;
        $this->request->post();
        $identitycardimgjust =request()->file("identitycardimgjust");
        $identitycardimgback =request()->file("identitycardimgback");
        $aa = $identitycardimgjust->move(ROOT_PATH.'public'.DS.'uploads');//图片保存路径
        $bb = $identitycardimgback->move(ROOT_PATH.'public'.DS.'uploads');//图片保存路径
        $a=$aa->getSaveName();//输出图片的路径及名字
        $b=$bb->getSaveName();
        //var_dump($a);exit;
        $data['identitycardimgjust'] = $a;
        $data['identitycardimgback'] = $b;
        $name['memberid'] = $data['memberid'] = input('memberid');
        $data['name'] = input('name');
        $data['idcardno'] = input('idcardno');
        $data['address'] = input('address');
        $data['phone'] = input('phone');
        $data['examine'] = 1;
        $data['operation'] = session('user.name');
        $data['bankcard'] = input('bankcard');
        $data['time'] =time();
//dump($data);exit;
        $re = db('member')->where($name)->find();
        if($re){
            echo "<script>alert('重复添加');javascript:history.go(-1);</script>";
        }
        $res=db('user')->insert($data);
        if($res){
            echo "<script>alert('添加信息成功');javascript:history.go(-1);</script>";
            //return ['code'=>1,'msg'=>'添加信息成功'];
        }else{
            echo "<script>alert('添加信息失败');javascript:history.go(-1);</script>";
            //return ['code'=>0,'msg'=>'添加信息失败'];
        }
    }
    public function expressdelete(){
        $user = session('user');
        //dump($user);exit;

        if(!$user){
            header("Refresh:1;url=login");
        }
        if(!$_GET){
            echo "<script>alert('提交不能为空');javascript:history.go(-1);</script>";
        }
        $data['id'] = trim($_GET['id']);
        $res=db('user')->where($data)->delete();
        if($res){
            echo "<script>alert('删除信息成功');javascript:history.go(-1);</script>";
            //return ['code'=>1,'msg'=>'删除信息成功'];

        }else{
            echo "<script>alert('删除信息失败');javascript:history.go(-1);</script>";
            //return ['code'=>0,'msg'=>'删除信息失败'];

        }
    }
    public function loan_det(){
        $user = session('user');
        if(!$user){
            header("Refresh:1;url=login");
        }
        $data['id'] = trim(input('id'));
        $res=db('user')->where($data)->find();
        $this->assign('list',$res);
        return $this->fetch();
    }
    public function expressupdate(){
        $user = session('user');
        //dump($user);exit;

        if(!$user){
            header("Refresh:1;url=login");
        }
        if(!$_POST) {
            echo "<script>alert('提交不能为空');javascript:history.go(-1);</script>";
            //$this->success('提交不能为空', 'express');
        }
//dump($_POST);exit;
        $id['id'] = trim($_POST['id']);
        if($id['id']){
        $id['id'] = trim($_POST['id']);
        $this->request->post();
        //var_dump($_FILES);exit;
        $userimg = request()->file("userimge");
        //var_dump($userimg);exit;
            if($userimg) {
                $cc = $userimg->move(ROOT_PATH . 'public' . DS . 'uploads');//图片保存路径
                $c = $cc->getSaveName();
                $data['userimg'] = $c;
            }
                $data['name'] = trim(input('name'));
                $data['province'] = trim(input('province'));
                $data['city'] = trim(input('city'));
                $data['county'] = trim(input('county'));
                $data['category'] = trim(input('category'));
                $data['practitionersdata'] = trim(input('practitionersdata'));
                $data['number'] = trim(input('number'));
                $data['star'] = trim(input('star'));
                $data['service'] = trim(input('service'));
                $data['gender'] = trim(input('gender'));
                $data['time'] = time();

        //dump($data);exit;
        $res=db('serviceuser')->where($id)->update($data);
        if($res){
            echo "<script>alert('更新信息成功');javascript:history.go(-1);</script>";
            //return ['code'=>1,'msg'=>'更新信息成功'];
        }else{
            echo "<script>alert('更新信息失败');javascript:history.go(-1);</script>";
        }
        }else{
            $this->request->post();
            //var_dump($_FILES);exit;

            $userimg = request()->file("userimge");
            //var_dump($userimg);exit;
            if($userimg) {
                $cc = $userimg->move(ROOT_PATH . 'public' . DS . 'uploads');//图片保存路径
                $c = $cc->getSaveName();
                $data['userimg'] = $c;
            }
            $data['name'] = trim(input('name'));
            $data['province'] = trim(input('province'));
            $data['city'] = trim(input('city'));
            $data['county'] = trim(input('county'));
            $data['category'] = trim(input('category'));
            $data['practitionersdata'] = trim(input('practitionersdata'));
            $data['number'] = trim(input('number'));
            $data['star'] = trim(input('star'));
            $data['service'] = trim(input('service'));
            $data['gender'] = trim(input('gender'));
            $data['time'] =time();
            $res = db('serviceuser')->insert($data);
            if($res){
                echo "<script>alert('添加信息成功');javascript:history.go(-1);</script>";
                //return ['code'=>1,'msg'=>'更新信息成功'];
            }else{
                echo "<script>alert('添加信息失败');javascript:history.go(-1);</script>";
            }
        }
    }
    public function loandelete(){
        $user = session('user');
        //dump($user);exit;

        if(!$user){
            header("Refresh:1;url=login");
        }
        if(!$_GET){
            $this->success('提交不能为空','express');
        }
        $data['id'] = trim($_GET['id']);
        $res=db('user')->where($data)->delete();
        if($res){
            echo "<script>alert('删除信息成功');javascript:history.go(-1);</script>";
            //return ['code'=>1,'msg'=>'删除信息成功'];

        }else{
            echo "<script>alert('删除信息失败');javascript:history.go(-1);</script>";
            //return ['code'=>0,'msg'=>'删除信息失败'];
        }
    }
    //已认证信息结束
    //未认证
    public function loan_examine(){
        $user = session('user');
        //dump($user);exit;

        if(!$user){
            header("Refresh:1;url=login");
        }
        //$operation['operation']=$user = session('user.name');
        //$examine['examine'] = 0;
//        $id[''] = input('');
//        $re = db('user')->where($id)->find();
//        if($re){
//
//        }
        $res=db('serviceuser')->order('id Desc')->paginate(10);
        $page =  $res->render();
        //dump($res);exit;
        $this->assign('page',$page);
        $this->assign('list',$res);
        return $this->fetch();
    }
    public function member_insert(){
        $user = session('user');
        //dump($user);exit;
        if(!$user){
            header("Refresh:1;url=login");
        }
        return $this->fetch();
    }
    public function memberadd(){
        $user = session('user');
        //dump($user);exit;

        if(!$user){
            header("Refresh:1;url=login");
        }
        if(!$_POST){
            return ['code' => 0, 'msg' => '提交不能为空'];
        }
        $name['name'] = $data['name'] = trim(input('name'));
        $data['password'] = trim(md5(md5(input('password'))));
        $data['phone'] = trim(input('phone'));
        $data['time'] = time();
        //dump($data);exit;
        $re = db('member')->where($name)->find();
        if($re){
            return ['code' => 3, 'msg' => '重复添加'];
        }
        $res=db('member')->insert($data);
        if($res){
            return ['code' => 1, 'msg' => '操作成功'];
        }else{
            return ['code' => 2, 'msg' => '操作失败'];
        }
    }
    public function member_det(){
        $user = session('user');
        //dump($user);exit;
        if(!$user){
            header("Refresh:1;url=login");
        }
        $data['id'] = trim(input('id'));
        $res=db('serviceuser')->where($data)->find();
        $this->assign('list',$res);
        return $this->fetch();
    }
    public function memberupdata(){
        $user = session('user');
        //dump($user);exit;
        if(!$user){
            header("Refresh:1;url=login");
        }
        if(!$_POST) {
            echo "<script>alert('提交不能为空');javascript:history.go(-1);</script>";
            //$this->success('提交不能为空', 'express');
        }
        $id['id'] = trim($_GET['id']);
        $data['name'] = input('name');
        if($_POST['password'] ) {
            $data['password'] = md5(md5(trim(input('password'))));
        }
        $data['phone'] = input('phone');
        $data['time'] = time();
        //dump($data);exit;
        $res=db('member')->where($id)->update($data);
        if($res){
            echo "<script>alert('修改成功');javascript:history.go(-1);</script>";
        }else{
            echo "<script>alert('修改失败');javascript:history.go(-1);</script>";
        }
    }
    public function memberdelect(){
        $user = session('user');
        //dump($user);exit;
        if(!$user){
            header("Refresh:1;url=login");
        }
        if(!$_GET){
            $this->success('提交不能为空','express');
        }
        $data['id'] = trim($_GET['id']);
        $res=db('serviceuser')->where($data)->delete();
        if($res){
            echo "<script>alert('删除信息成功');javascript:history.go(-1);</script>";
            //return ['code'=>1,'msg'=>'删除信息成功'];
        }else{
            echo "<script>alert('删除信息失败');javascript:history.go(-1);</script>";
            //return ['code'=>0,'msg'=>'删除信息失败'];
        }
    }
    public function user(){
        $user = session('user');
        if(!$user){
            header("Refresh:1;url=login");
        }
        $res = db('member')->select();
    }
    public function contacts(){
        $user = session('user');
        if(!$user){
            header("Refresh:1;url=login");
        }
        $id['memberid'] = input('id');
        $res = db('contacts')->where($id)->select();
        $this->assign('list',$res);
        return $this->fetch();
    }
    public function query(){
        $user = session('user');
        if(!$user){
            header("Refresh:1;url=login");
        }
        $id['phone'] = trim(input('query'));
        $res = db('member')->where($id)->find();
//dump($res);exit;
        $this->assign('list',$res);
        return $this->fetch();
    }
}